//============================================================================
// Name        : GreenEyesOffloadingServer.cpp
// Author      : Alessandro Bramati
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<arpa/inet.h>
#include<unistd.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<opencv2/opencv.hpp>
#include<opencv2/features2d/features2d.hpp>
#include<opencv2/highgui/highgui.hpp>
#include "Utility.h"
using namespace std;
using namespace cv;
#define BUFLEN 1400

int main()
{
	int type,clientsNumber,loads,threshold,blocks,octave,test;
	float overlap;
	cout<<"Setting up TCP server...."<<endl;
	cout<<"Clients number (0 to 4):"<<endl;
	cin>>clientsNumber;
	if(clientsNumber>0)
	{
		cout<<"Test repeatability (0) yes (1) no"<<endl;
		cin>>test;
		if(test == 0)
		{
			cout<<"Image overlap (%):"<<endl;
			scanf("%f",&overlap);
			testRepeatability(clientsNumber,overlap);
			return 0;
		}
		else
		{
			cout<<"Unicast (0) broadcast (1)"<<endl;
			cin>>type;
			/*
			if(type==1)
			{
				cout<<"Blocks:"<<endl;
				cin>>blocks;
			}
			*/
			cout<<"Image overlap (%):"<<endl;
			scanf("%f",&overlap);
			cout<<"Static loads (0) optimal loads (1):"<<endl;
			cin>>loads;
			cout<<"Threshold: "<<endl;
			cin>>threshold;
			cout<<"Octave: "<<endl;
			cin>>octave;
			if(type==0)
				unicastF(clientsNumber,overlap,loads,threshold,octave);
			else
				broadcast(clientsNumber,overlap,loads,threshold,blocks,octave);
			return 0;
		}
	}
	else
	{
		type=0;
		overlap=0;
		loads=0;
		cout<<"Threshold: "<<endl;
		cin>>threshold;
		cout<<"Octave: "<<endl;
		cin>>octave;
		if(type==0)
			unicastF(clientsNumber,overlap,loads,threshold,octave);
		else
			broadcast(clientsNumber,overlap,loads,threshold,blocks,octave);
		return 0;
	}

	//VideoCapture cap(0);
	//if(!cap.isOpened())  // check if we succeeded
	//	printErrorLog("Camera not working");

}
